package the.one.weather.model;

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;

import org.litepal.LitePal;
import org.litepal.crud.LitePalSupport;

import java.util.ArrayList;
import java.util.List;

import the.one.weather.util.LitePalUtil;
import the.one.weather.util.WeatherUtil;

/**
 * @author The one
 * @date 2019/5/8 0008
 * @describe TODO
 * @email 625805189@qq.com
 * @remark
 */
public class Weather extends LitePalSupport implements Parcelable {

    /**
     * currentCity : 碧江区
     * pm25 : 25
     * index : [{"des":"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。","tipt":"穿衣指数","title":"穿衣","zs":"较冷"},{"des":"不宜洗车，未来24小时内有雨，如果在此期间洗车，雨水和路上的泥水可能会再次弄脏您的爱车。","tipt":"洗车指数","title":"洗车","zs":"不宜"},{"des":"天冷空气湿度大，易发生感冒，请注意适当增加衣服，加强自我防护避免感冒。","tipt":"感冒指数","title":"感冒","zs":"易发"},{"des":"有降水，推荐您在室内进行健身休闲运动；若坚持户外运动，须注意携带雨具并注意避雨防滑。","tipt":"运动指数","title":"运动","zs":"较不宜"},{"des":"属弱紫外线辐射天气，无需特别防护。若长期在户外，建议涂擦SPF在8-12之间的防晒护肤品。","tipt":"紫外线强度指数","title":"紫外线强度","zs":"最弱"}]
     * weather_data : [{"date":"周二 05月07日 (实时：13℃)","dayPictureUrl":"http://api.map.baidu.com/images/weather/day/xiaoyu.png","nightPictureUrl":"http://api.map.baidu.com/images/weather/night/xiaoyu.png","weather":"小雨","wind":"无持续风向微风","temperature":"16 ~ 12℃"},{"date":"周三","dayPictureUrl":"http://api.map.baidu.com/images/weather/day/yin.png","nightPictureUrl":"http://api.map.baidu.com/images/weather/night/yin.png","weather":"阴","wind":"无持续风向微风","temperature":"22 ~ 12℃"},{"date":"周四","dayPictureUrl":"http://api.map.baidu.com/images/weather/day/duoyun.png","nightPictureUrl":"http://api.map.baidu.com/images/weather/night/duoyun.png","weather":"多云","wind":"无持续风向微风","temperature":"25 ~ 14℃"},{"date":"周五","dayPictureUrl":"http://api.map.baidu.com/images/weather/day/duoyun.png","nightPictureUrl":"http://api.map.baidu.com/images/weather/night/baoyu.png","weather":"多云转暴雨","wind":"无持续风向微风","temperature":"26 ~ 17℃"}]
     */

    private int id;
    private String weather;
    private String temperature;
    private String lbs;
    private long addTime;

    @SerializedName("currentCity")
    private String currentCity;
    @SerializedName("pm25")
    private String pm25;
    @SerializedName("index")
    private List<WeatherTips> tips = new ArrayList<>();
    @SerializedName("weather_data")
    private List<WeatherFuture> futures = new ArrayList<>();


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCurrentCity() {
        return currentCity;
    }

    public void setCurrentCity(String currentCity) {
        this.currentCity = currentCity;
    }

    public String getWeather() {
        return weather;
    }

    public int getWeatherRes() {
        return WeatherUtil.parseWeatherImage(weather);
    }

    public int getWeatherColor() {
        return WeatherUtil.parseWeatherColor(weather);
    }

    public int getWeatherVideo() {
        return WeatherUtil.parseWeatherVideo(weather);
    }

    public String getTemperature() {
        return temperature;
    }

    public String getPm25() {
        return pm25;
    }

    public void setPm25(String pm25) {
        this.pm25 = pm25;
    }

    public List<WeatherTips> getTips() {
        return tips;
    }

    public void setTips(List<WeatherTips> tips) {
        LitePalUtil.deleteWeatherTips(this);
        LitePal.saveAll(tips);
        this.tips = tips;
    }

    public List<WeatherFuture> getFutures() {
        return futures;
    }

    public void setFutures(List<WeatherFuture> futures) {
        LitePalUtil.deleteWeatherFutures(this);
        LitePal.saveAll(futures);
        this.futures = futures;
    }

    public boolean isLbs() {
        return lbs.equals(LitePalUtil.isLbs);
    }

    public void setLbs(String lbs) {
        this.lbs = lbs;
    }

    public String getLbs() {
        return lbs;
    }

    public long getAddTime() {
        return addTime;
    }

    public void setAddTime(long addTime) {
        this.addTime = addTime;
    }

    public void initWeather() {
        if (null == futures || futures.size() == 0) {
            return;
        }
        WeatherFuture future = futures.get(0);
        if (null == future) {
            return;
        }
        String temp = future.getDate();
        temperature = temp.substring(temp.indexOf("：") + 1, temp.indexOf("℃"));
        weather = WeatherUtil.parseWeather(future.getWeather());
    }

    @Override
    public String toString() {
        return "\nWeather{" +
                "id=" + id +
                ", currentCity='" + currentCity + '\'' +
                ", lbs='" + lbs + '\'' +
                ", addTime=" + addTime +
                ", futures=" + futures.toString() +
                ", weather='" + weather + '\'' +
                ", temperature='" + temperature + '\'' +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.weather);
        dest.writeString(this.temperature);
        dest.writeString(this.lbs);
        dest.writeLong(this.addTime);
        dest.writeString(this.currentCity);
        dest.writeString(this.pm25);
        dest.writeList(this.tips);
        dest.writeList(this.futures);
    }

    public Weather() {
    }

    protected Weather(Parcel in) {
        this.id = in.readInt();
        this.weather = in.readString();
        this.temperature = in.readString();
        this.lbs = in.readString();
        this.addTime = in.readLong();
        this.currentCity = in.readString();
        this.pm25 = in.readString();
        this.tips = new ArrayList<WeatherTips>();
        in.readList(this.tips, WeatherTips.class.getClassLoader());
        this.futures = new ArrayList<WeatherFuture>();
        in.readList(this.futures, WeatherFuture.class.getClassLoader());
    }

    public static final Parcelable.Creator<Weather> CREATOR = new Parcelable.Creator<Weather>() {
        @Override
        public Weather createFromParcel(Parcel source) {
            return new Weather(source);
        }

        @Override
        public Weather[] newArray(int size) {
            return new Weather[size];
        }
    };
}
